/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mundial;

import java.awt.EventQueue;
import java.beans.Beans;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.persistence.RollbackException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.jdesktop.beansbinding.BindingGroup;
import org.jgap.Configuration;

/**
 *
 * @author jorge
 */
public class equipoMundial extends JPanel {
    
    public equipoMundial() {
        try {
            UIManager.setLookAndFeel("com.alee.laf.WebLookAndFeel");
            initComponents();
            if (!Beans.isDesignTime()) {
                entityManager.getTransaction().begin();
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(equipoMundial.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(equipoMundial.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(equipoMundial.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(equipoMundial.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("equipo?zeroDateTimeBehavior=convertToNullPU").createEntityManager();
        query = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT r FROM RankingFifa r");
        list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
        masterScrollPane = new javax.swing.JScrollPane();
        masterTable = new javax.swing.JTable();
        rankingLabel = new javax.swing.JLabel();
        grupoLabel = new javax.swing.JLabel();
        copasLabel = new javax.swing.JLabel();
        partido3Label = new javax.swing.JLabel();
        partido2Label = new javax.swing.JLabel();
        partido1Label = new javax.swing.JLabel();
        nombreLabel = new javax.swing.JLabel();
        rankingField = new javax.swing.JTextField();
        grupoField = new javax.swing.JTextField();
        copasField = new javax.swing.JTextField();
        partido3Field = new javax.swing.JTextField();
        partido2Field = new javax.swing.JTextField();
        partido1Field = new javax.swing.JTextField();
        nombreField = new javax.swing.JTextField();
        saveButton = new javax.swing.JButton();
        refreshButton = new javax.swing.JButton();
        newButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        calculateButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtconsola = new javax.swing.JTextArea();

        FormListener formListener = new FormListener();

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, masterTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nombre}"));
        columnBinding.setColumnName("Nombre");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${ranking}"));
        columnBinding.setColumnName("Ranking");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${grupo}"));
        columnBinding.setColumnName("Grupo");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${copas}"));
        columnBinding.setColumnName("Copas");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${partido3}"));
        columnBinding.setColumnName("Partido3");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${partido2}"));
        columnBinding.setColumnName("Partido2");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${partido1}"));
        columnBinding.setColumnName("Partido1");
        columnBinding.setColumnClass(Integer.class);
        bindingGroup.addBinding(jTableBinding);

        masterScrollPane.setViewportView(masterTable);

        rankingLabel.setText("Ranking:");

        grupoLabel.setText("Grupo:");

        copasLabel.setText("Copas:");

        partido3Label.setText("Partido3:");

        partido2Label.setText("Partido2:");

        partido1Label.setText("Partido1:");

        nombreLabel.setText("Nombre:");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.ranking}"), rankingField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), rankingField, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        rankingField.addActionListener(formListener);
        rankingField.addKeyListener(formListener);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.grupo}"), grupoField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), grupoField, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        grupoField.addKeyListener(formListener);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.copas}"), copasField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), copasField, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        copasField.addKeyListener(formListener);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.partido3}"), partido3Field, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), partido3Field, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        partido3Field.addKeyListener(formListener);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.partido2}"), partido2Field, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), partido2Field, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.partido1}"), partido1Field, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), partido1Field, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.nombre}"), nombreField, org.jdesktop.beansbinding.BeanProperty.create("text"));
        binding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), nombreField, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        nombreField.addKeyListener(formListener);

        saveButton.setText("Save");
        saveButton.addActionListener(formListener);

        refreshButton.setText("Refresh");
        refreshButton.addActionListener(formListener);

        newButton.setText("New");
        newButton.addActionListener(formListener);

        deleteButton.setText("Delete");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), deleteButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        deleteButton.addActionListener(formListener);

        calculateButton.setText("Calculate");
        calculateButton.addActionListener(formListener);

        txtconsola.setColumns(20);
        txtconsola.setRows(5);
        jScrollPane1.setViewportView(txtconsola);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(calculateButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(newButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(refreshButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveButton))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(rankingLabel)
                                    .addComponent(grupoLabel)
                                    .addComponent(copasLabel)
                                    .addComponent(partido3Label)
                                    .addComponent(partido2Label)
                                    .addComponent(partido1Label)
                                    .addComponent(nombreLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(nombreField)
                                    .addComponent(rankingField, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE)
                                    .addComponent(grupoField, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE)
                                    .addComponent(copasField, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE)
                                    .addComponent(partido3Field, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE)
                                    .addComponent(partido2Field, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE)
                                    .addComponent(partido1Field, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE))))))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {deleteButton, newButton, refreshButton, saveButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(masterScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nombreLabel)
                    .addComponent(nombreField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rankingLabel)
                    .addComponent(rankingField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(grupoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(grupoLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(copasField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(copasLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(partido3Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(partido3Label))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(partido2Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(partido2Label))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(partido1Field, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(partido1Label))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveButton)
                    .addComponent(refreshButton)
                    .addComponent(deleteButton)
                    .addComponent(newButton)
                    .addComponent(calculateButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
                .addContainerGap())
        );

        bindingGroup.bind();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener, java.awt.event.KeyListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == saveButton) {
                equipoMundial.this.saveButtonActionPerformed(evt);
            }
            else if (evt.getSource() == refreshButton) {
                equipoMundial.this.refreshButtonActionPerformed(evt);
            }
            else if (evt.getSource() == newButton) {
                equipoMundial.this.newButtonActionPerformed(evt);
            }
            else if (evt.getSource() == deleteButton) {
                equipoMundial.this.deleteButtonActionPerformed(evt);
            }
            else if (evt.getSource() == calculateButton) {
                equipoMundial.this.calculateButtonActionPerformed(evt);
            }
            else if (evt.getSource() == rankingField) {
                equipoMundial.this.rankingFieldActionPerformed(evt);
            }
        }

        public void keyPressed(java.awt.event.KeyEvent evt) {
        }

        public void keyReleased(java.awt.event.KeyEvent evt) {
        }

        public void keyTyped(java.awt.event.KeyEvent evt) {
            if (evt.getSource() == copasField) {
                equipoMundial.this.copasFieldKeyTyped(evt);
            }
            else if (evt.getSource() == partido3Field) {
                equipoMundial.this.partido3FieldKeyTyped(evt);
            }
            else if (evt.getSource() == rankingField) {
                equipoMundial.this.rankingFieldKeyTyped(evt);
            }
            else if (evt.getSource() == nombreField) {
                equipoMundial.this.nombreFieldKeyTyped(evt);
            }
            else if (evt.getSource() == grupoField) {
                equipoMundial.this.grupoFieldKeyTyped(evt);
            }
        }
    }// </editor-fold>//GEN-END:initComponents

    

    @SuppressWarnings("unchecked")
    private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
        entityManager.getTransaction().rollback();
        entityManager.getTransaction().begin();
        java.util.Collection data = query.getResultList();
        for (Object entity : data) {
            entityManager.refresh(entity);
        }
        list.clear();
        list.addAll(data);
        txtconsola.setText(" ");
        
    }//GEN-LAST:event_refreshButtonActionPerformed
    
    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        int[] selected = masterTable.getSelectedRows();
        List<mundial.RankingFifa> toRemove = new ArrayList<mundial.RankingFifa>(selected.length);
        for (int idx = 0; idx < selected.length; idx++) {
            mundial.RankingFifa r = list.get(masterTable.convertRowIndexToModel(selected[idx]));
            toRemove.add(r);
            entityManager.remove(r);
        }
        list.removeAll(toRemove);
    }//GEN-LAST:event_deleteButtonActionPerformed
    
    private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
        mundial.RankingFifa r = new mundial.RankingFifa();
        entityManager.persist(r);
        list.add(r);
        int row = list.size() - 1;
        masterTable.setRowSelectionInterval(row, row);
        masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));
    }//GEN-LAST:event_newButtonActionPerformed

    public JTextField getCopasField() {
        return copasField;
    }

    public void setCopasField(JTextField copasField) {
        this.copasField = copasField;
    }

    public JTextField getGrupoField() {
        return grupoField;
    }

    public void setGrupoField(JTextField grupoField) {
        this.grupoField = grupoField;
    }

    public List<RankingFifa> getList() {
        return list;
    }

    public void setList(List<RankingFifa> list) {
        this.list = list;
    }

    public JTable getMasterTable() {
        return masterTable;
    }

    public void setMasterTable(JTable masterTable) {
        this.masterTable = masterTable;
    }

    public JTextField getNombreField() {
        return nombreField;
    }

    public void setNombreField(JTextField nombreField) {
        this.nombreField = nombreField;
    }

    public JTextField getPartido1Field() {
        return partido1Field;
    }

    public void setPartido1Field(JTextField partido1Field) {
        this.partido1Field = partido1Field;
    }

    public JTextField getPartido2Field() {
        return partido2Field;
    }

    public void setPartido2Field(JTextField partido2Field) {
        this.partido2Field = partido2Field;
    }

    public JTextField getPartido3Field() {
        return partido3Field;
    }

    public void setPartido3Field(JTextField partido3Field) {
        this.partido3Field = partido3Field;
    }

    public JTextField getRankingField() {
        return rankingField;
    }

    public void setRankingField(JTextField rankingField) {
        this.rankingField = rankingField;
    }
    
    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        try {
            entityManager.getTransaction().commit();
            entityManager.getTransaction().begin();
        } catch (RollbackException rex) {
            rex.printStackTrace();
            entityManager.getTransaction().begin();
            List<mundial.RankingFifa> merged = new ArrayList<mundial.RankingFifa>(list.size());
            for (mundial.RankingFifa r : list) {
                merged.add(entityManager.merge(r));
                
            }
            
            list.clear();
            list.addAll(merged);
        }
    }//GEN-LAST:event_saveButtonActionPerformed


    public JTextArea getTxtconsola() {
        return txtconsola;
    }

    public void setTxtconsola(JTextArea txtconsola) {
        this.txtconsola = txtconsola;
    }
    
    private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calculateButtonActionPerformed
// TODO add your handling code here:
     try {
            TestMundialFitness test = new TestMundialFitness();
       
            
            test.initialize(" ");
            test.testSelectFittestPartidos();
      
            
            txtconsola.setText(".................."+"\n"+"genes Escogidos: "+test.getSolucion2()+"\n"+"valor del fitness: "+test.getSolucion()+"\n"+"..............."+"Posibles ganadores: "+test.getResultado());
          Configuration.reset();   
     } catch (Exception ex) {
            Logger.getLogger(equipoMundial.class.getName()).log(Level.SEVERE, null, ex);
        }
     
    
    }//GEN-LAST:event_calculateButtonActionPerformed

    private void copasFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_copasFieldKeyTyped
        // TODO add your handling code here:
        char car=evt.getKeyChar();
        
        if((car<'0'||car>'9')) evt.consume();
        
    }//GEN-LAST:event_copasFieldKeyTyped

    private void partido3FieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_partido3FieldKeyTyped

    }//GEN-LAST:event_partido3FieldKeyTyped

    private void rankingFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rankingFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rankingFieldActionPerformed

    private void rankingFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_rankingFieldKeyTyped
// TODO add your handling code here:
   int car=evt.getKeyChar();
   if((car<1||car>60)) evt.consume();     
    }//GEN-LAST:event_rankingFieldKeyTyped

    private void nombreFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nombreFieldKeyTyped
        // TODO add your handling code here:
    char car = evt.getKeyChar();
    if((car<'a' || car>'z') && (car<'A' || car>'Z')) evt.consume();

    }//GEN-LAST:event_nombreFieldKeyTyped

    private void grupoFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_grupoFieldKeyTyped
        // TODO add your handling code here:
        char car = evt.getKeyChar();
        if(grupoField.getText().length()==1) evt.consume();
    if((car<'a' || car>'h') && (car<'A' || car>'H')) evt.consume();
    }//GEN-LAST:event_grupoFieldKeyTyped

    public JButton getCalculateButton() {
        return calculateButton;
    }

    public void setCalculateButton(JButton calculateButton) {
        this.calculateButton = calculateButton;
    }

    public JLabel getCopasLabel() {
        return copasLabel;
    }

    public void setCopasLabel(JLabel copasLabel) {
        this.copasLabel = copasLabel;
    }

    public JButton getDeleteButton() {
        return deleteButton;
    }

    public void setDeleteButton(JButton deleteButton) {
        this.deleteButton = deleteButton;
    }

    public EntityManager getEntityManager() {
        return entityManager;
    }

    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    public JLabel getGrupoLabel() {
        return grupoLabel;
    }

    public void setGrupoLabel(JLabel grupoLabel) {
        this.grupoLabel = grupoLabel;
    }

    public JScrollPane getMasterScrollPane() {
        return masterScrollPane;
    }

    public void setMasterScrollPane(JScrollPane masterScrollPane) {
        this.masterScrollPane = masterScrollPane;
    }

    public JButton getNewButton() {
        return newButton;
    }

    public void setNewButton(JButton newButton) {
        this.newButton = newButton;
    }

    public JLabel getNombreLabel() {
        return nombreLabel;
    }

    public void setNombreLabel(JLabel nombreLabel) {
        this.nombreLabel = nombreLabel;
    }

    public JLabel getPartido1Label() {
        return partido1Label;
    }

    public void setPartido1Label(JLabel partido1Label) {
        this.partido1Label = partido1Label;
    }

    public JLabel getPartido2Label() {
        return partido2Label;
    }

    public void setPartido2Label(JLabel partido2Label) {
        this.partido2Label = partido2Label;
    }

    public JLabel getPartido3Label() {
        return partido3Label;
    }

    public void setPartido3Label(JLabel partido3Label) {
        this.partido3Label = partido3Label;
    }

    public Query getQuery() {
        return query;
    }

    public void setQuery(Query query) {
        this.query = query;
    }

    public JLabel getRankingLabel() {
        return rankingLabel;
    }

    public void setRankingLabel(JLabel rankingLabel) {
        this.rankingLabel = rankingLabel;
    }

    public JButton getRefreshButton() {
        return refreshButton;
    }

    public void setRefreshButton(JButton refreshButton) {
        this.refreshButton = refreshButton;
    }

    public JButton getSaveButton() {
        return saveButton;
    }

    public void setSaveButton(JButton saveButton) {
        this.saveButton = saveButton;
    }

    public BindingGroup getBindingGroup() {
        return bindingGroup;
    }

    public void setBindingGroup(BindingGroup bindingGroup) {
        this.bindingGroup = bindingGroup;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton calculateButton;
    private javax.swing.JTextField copasField;
    private javax.swing.JLabel copasLabel;
    private javax.swing.JButton deleteButton;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JTextField grupoField;
    private javax.swing.JLabel grupoLabel;
    private javax.swing.JScrollPane jScrollPane1;
    private java.util.List<mundial.RankingFifa> list;
    private javax.swing.JScrollPane masterScrollPane;
    private javax.swing.JTable masterTable;
    private javax.swing.JButton newButton;
    private javax.swing.JTextField nombreField;
    private javax.swing.JLabel nombreLabel;
    private javax.swing.JTextField partido1Field;
    private javax.swing.JLabel partido1Label;
    private javax.swing.JTextField partido2Field;
    private javax.swing.JLabel partido2Label;
    private javax.swing.JTextField partido3Field;
    private javax.swing.JLabel partido3Label;
    private javax.persistence.Query query;
    private javax.swing.JTextField rankingField;
    private javax.swing.JLabel rankingLabel;
    private javax.swing.JButton refreshButton;
    private javax.swing.JButton saveButton;
    private javax.swing.JTextArea txtconsola;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    public static void main(String[] args) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(equipoMundial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(equipoMundial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(equipoMundial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(equipoMundial.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame();
                frame.setContentPane(new equipoMundial());
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.pack();
                frame.setVisible(true);
            }
        });
    }
}
